/**
 * Created by Administrator on 2016/8/1.
 */

var sceniclistDao = require('../dao/sceniclistDao');
var uuid = require('node-uuid');
var async = require('async');

//获取景点列表
exports.sceniclist=function (callback) {
    sceniclistDao.sceniclist(function (err,datas) {
        callback(err,datas);
    })
}


//景区带条件列表
exports.shoplist=function (params,callback) {
    sceniclistDao.shoplist(params,function (err,datas) {
        callback(err,datas);
    })
}


//景区所有商品列表
exports.allshop=function (spotid,callback) {
    sceniclistDao.allshop(spotid,function (err,datas) {
        callback(err,datas);
    })
}

//获取条件下商品列表
exports.findgoods=function (params,callback) {
    sceniclistDao.findgoods(params,function (err,datas) {
        callback(err,datas);
    })
}

//添加景点
exports.addsceniclist=function (params,callback) {
    var obj = {
        id: uuid.unparse(uuid.v4(null, new Buffer(32), 0)),
        spotname:params.scenicname,
        spotdesc:params.scenicdes,
        createBy: params.userid,
        createAt: new Date(),
        updateAt:new  Date(),
        status: 1
    };
    sceniclistDao.addsceniclist(obj,function (err,data) {
        callback(err,data);
    })
}

//景区票务列表
exports.shoplist=function (sid,callback) {
    sceniclistDao.shoplist(sid,function (err,data) {
        callback(err,data);
    })
}

//添加商品信息
exports.addticketlist=function (params,callback) {
    var obj = {
        id: uuid.unparse(uuid.v4(null, new Buffer(32), 0)),
        name:params.tickername,
        description:params.ticketdes,
        price:params.ticketprice,
        type:params.ticketprice,
        specialtip:params.tickettype,
        createBy: params.userid,
        createAt: new Date(),
        updateAt:new  Date(),
        status: 1
    };
    sceniclistDao.addticketlist(obj,function (err,data) {
        callback(err,data);
    })
}

//获取票的详情信息
exports.ticketdetail=function (id,callback) {
    sceniclistDao.ticketdetail(id,function (err,data) {
        callback(err,data);
    })
}
//确认预定后保存预定商品信息
exports.reservemessage=function (obj,callback) {
    obj.id = uuid.unparse(uuid.v4(null, new Buffer(32), 0));
    obj.status = 1;
    obj.orderstatus = 4;
    sceniclistDao.reservemessage(obj,function (err,data) {
        callback(err,data);
    })
}

//更新订单信息
exports.updatereservemes=function (payid,payment,callback) {
    sceniclistDao.updatereservemes(payid,payment,function (err,data) {
        callback(err,data);
    })
}

//保存购物车
exports.savetocart=function (obj,callback) {
    obj.id = uuid.unparse(uuid.v4(null, new Buffer(32), 0));
    obj.status = 1;
    sceniclistDao.savetocart(obj,function (err,data) {

        callback(err,data);
    })
}


//单个商品预定
exports.onlyreserve=function (params,callback) {
    sceniclistDao.onlyreserve(params,function (err,data) {
        sceniclistDao.upstatus(params,function (err,data2) {
            callback(err,{data:data,data2:data2});
        })
    })
}